#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UIPushButton.h>
#import <UIKit/UIThreePartButton.h>
#import <UIKit/UINavigationBar.h>
#import <UIKit/UIWindow.h>
#import <UIKit/UIView-Hierarchy.h>
#import <UIKit/UIHardware.h>
#import <UIKit/UISectionTable.h>
#import <UIKit/UITableCell.h>
#import <UIKit/UITableColumn.h>
#import "iMarks.h"
#import "SubjectView.h"
#import "SubjectsManager.h"
#import "SubjectDetailView.h"

@implementation iMarks

- (void) applicationDidFinishLaunching: (id) unused
{
    UIWindow *window;
    struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
   
	rect.origin.x = rect.origin.y = 0.0f;

    window = [[UIWindow alloc] initWithContentRect: [UIHardware
        fullScreenApplicationContentRect]];

    [window orderFront: self];
    [window makeKey: self];
    [window _setHidden: NO];
	
	mainView = [[UIView alloc] initWithFrame: rect];
	
	marksView = [[MarksView alloc]
				 initWithFrame: CGRectMake(0.0f, 0.0f, rect.size.width, 
										   rect.size.height)];

    [mainView addSubview: marksView];
	
    [window setContentView: mainView];
		
	defaultPNG = [self createApplicationDefaultPNG];
}

- (void)applicationWillTerminate {
	if (defaultPNG != nil) {
		NSString *pathToDefault = [NSString stringWithFormat:@"%@/Default.png", 
								   [[NSBundle mainBundle] bundlePath]];
		NSURL *urlToDefault = [NSURL fileURLWithPath:pathToDefault];
		CGImageDestinationRef dest = CGImageDestinationCreateWithURL(
														(CFURLRef)urlToDefault, 
														CFSTR("public.png"), 1,
														NULL);
		CGImageDestinationAddImage(dest, defaultPNG, NULL);
		CGImageDestinationFinalize(dest);
		CFRelease(defaultPNG);
	}
	[[SubjectsManager sharedInstance] writeFile];
}

@end